package com.hiwan.system.enumeration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum ReturnCodeEnum{

	success(0, "处理成功"),
	exception(98, "处理异常"),
	error(99, "处理失败");
	
	private final int code;
	private final String desc;
	
	ReturnCodeEnum(int code, String desc){
		this.code = code;
		this.desc = desc;
	}
	
	public int getCode() {
		return code;
	}
	
	public String getDesc() {
		return desc;
	}
	
    public static String parse(int code) {
        for (ReturnCodeEnum s : ReturnCodeEnum.values()) {
            if (s.code == code) {
                return s.desc;
            }
        }
        return null;
    }
    
    public static List<Map<String, String>> getAllEnum() {
        List<Map<String, String>> l = new ArrayList<Map<String, String>>();
        ReturnCodeEnum[] s = ReturnCodeEnum.values();
        for (ReturnCodeEnum companyType : s) {
            Map<String, String> maps = new HashMap<String, String>();
            maps.put("code", String.valueOf(companyType.code));
            maps.put("desc", companyType.desc);
            l.add(maps);
        }
        return l;
    }
}